struct ListNode* rev(struct ListNode *h){
   struct ListNode *p=NULL,*r=NULL;
    while(h!=NULL){
      p=h->next;
      h->next=r;
      r=h;
      h=p;
    }
    return r;
 }
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){
      int t=0,k;
      l1=rev(l1);
      l2=rev(l2);
      
      struct ListNode* p,*r;
      p=(struct ListNode *)malloc(sizeof(struct ListNode));
      p->next=NULL;
      while(l1!=NULL||l2!=NULL){
        int x= l1==NULL?0:l1->val;
        int y= l2==NULL?0:l2->val;
        k=x+y+t;
        r=(struct ListNode *)malloc(sizeof(struct ListNode));
        r->val=k%10;
        t=k/10;
        r->next=p->next;
        p->next=r;
        if(l1!=NULL) l1=l1->next;
        if(l2!=NULL) l2=l2->next;
      }
      if(t>0){
        p->val=t;
        return p;
      }else{
        return p->next;
     }
    
}
